package com.ht.aems.fesmonitor;

import com.ht.aems.fesmodel.FesServer;
import org.apache.log4j.Logger;

import java.rmi.Naming;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2007-4-14
 *         Time: 13:36:13
 */
public class ServerFactory {

    private static Logger log = Logger.getLogger(ServerFactory.class);

    public static String currentServerAddress;

    static {
    }

    public static String getCurrentServerAddress() {
        return currentServerAddress;
    }

    public static void setCurrentServerAddress(String currentServerAddress) {
        ServerFactory.currentServerAddress = currentServerAddress;
    }

    public static FesServer getServer() {
        if (currentServerAddress == null)
            return null;
        return getServer(currentServerAddress);
    }


    public static FesServer getServer(String address) {
        try {
            FesServer server = (FesServer) Naming.lookup("//" + address + "/" + FesServer.class.getName());
            if (server != null)
                return server;
        } catch (Exception e) {
            e.printStackTrace();
            log.warn("can find server at " + "//" + address + "/" + FesServer.class.getName() + ":" + e);
        }
        return null;
    }
}
